#Fig_3_6

plot_data<-read.csv("QH_recurrence.csv")

plot_data %>%
  group_by(future_recur, time_period, level) %>%
  mutate(Freq=sum(Freq)) %>%
  dplyr::select(!outcome) %>%
  distinct() %>%
  ggplot(aes(y=Freq, x=factor(level, levels = c("Dyad", "Conflict", "Country")), fill=
               factor(future_recur, levels=c(1,0), labels=c("Yes", "No"))))+
  geom_bar(stat="identity", position="fill")+
  facet_wrap(~factor(time_period, levels = c("1946_to_1989", "1990_to_2021"),labels = c("1946-1989", "1990-2019")))+
  labs(fill="Recurrence", x="Level", y="Proportion") +
  theme_bw() 
ggsave("Fig3.png", path=imdir, width=6, height = 4, units="in")

plot_data %>%
  ggplot(aes(y=Freq, x=
               factor(outcome, levels = c(1,3,4), labels= c("Peace Agreement", "Government Victory", "Rebel Victory")), fill=
               factor(future_recur, levels=c(1,0), labels=c("Yes", "No"))))+
  geom_bar(stat="identity", position="fill")+
  labs(fill="Recurrence", x="Outcome", y="Proportion")+
  theme_bw()+
  theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))+
  facet_wrap(~factor(time_period, levels = c("1946_to_1989", "1990_to_2021"),labels = c("1946-1989", "1990-2019"))+
               factor(level, levels = c("Dyad", "Conflict", "Country")))
ggsave("Fig6.png", path=imdir, width=6, height = 6, units="in")
